
function bookSellType(input){
	if(input.value==0){
		document.getElementById('price').setAttribute("readonly","readonly");
		document.getElementById('price').value="0.0";
	}else{
		document.getElementById('price').removeAttribute("readonly","readonly");
		document.getElementById('price').value="";
	}
}

/**
 * 当鼠标移进书籍名称输入文本框的时候将会触发这个事件
 */
function focusBookName() {
	document.getElementById("check_book_name").innerHTML = "书籍名称长度不能超过50";
	document.getElementById("check_book_name").className = "add_info";
	document.getElementById("bookName").className = "input_txtFocus";
}
function focusType() {
	document.getElementById("check_book_type").innerHTML = "书籍的类型不能为空。请选择！";
	document.getElementById("check_book_type").className = "add_info";
	document.getElementById("bookTypeName").className = "input_txtFocus";
}

/**
 * 名称提示
 */
function blurBookName() {
	var book_name = document.getElementById("bookName");
	book_name.className = "input_text";
	var bookName = book_name.value;

	var span = document.getElementById("check_book_name");
	if(bookName.length <= 0) {
		span.innerHTML = "书籍名称长度必须大于0";
		span.className = "add_error";
		return false;
	} else if(bookName.length > 50) {
		span.innerHTML = "书籍名称长度不能大于50";
		span.className = "add_error";
		return false;
	} else {
		span.innerHTML = "ok";
		span.className = "add_succeed";
		return true;
	}
}
function focusType() {
	var value = document.getElementById("bookTypeName").value;
	if(value.length<1 ||value==""){
		document.getElementById("check_book_type").innerHTML="请选择书籍分类！"
			document.getElementById("check_book_type").className = "add_error";
		return false;
	}
	document.getElementById("check_book_type").innerHTML="OK";
	document.getElementById("check_book_type").className = "add_succeed";
	return true;
}

/*当价格文本区域获得焦点的时候*/
function focusPrice() {
	document.getElementById("check_book_price").innerHTML = "长度不能大于10，并且只能为数字或者带有一个小数点";
	document.getElementById("check_book_price").className = "add_info";
	document.getElementById("price").className = "input_txtFocus";
}

/*当价格输入文本框失去焦点的时候*/
function blurPrice() {
	var book_price = document.getElementById("price");
	book_price.className = "input_text";
	var bookPrice = book_price.value;

	var span = document.getElementById("check_book_price");
	/*验证填写的书籍是否正确*/
	var reg = /^([0-9]{1,10})\.{0,1}([0-9]{0,10})$/g;
	if(bookPrice.length <= 0) {
		span.innerHTML = "收费类型的书籍必须填写价格";
		span.className = "add_error";
		return false;
	} else if(bookPrice.length > 10) {
		span.innerHTML = "书籍的价格长度不能超过10";
		span.className = "add_error";
		return false;
	} else if(reg.test(bookPrice) == false) {
		span.innerHTML = "请检查是否填入非法的数字——只能有一个小数点 ";
		span.className = "add_error";
		return false;
	} else {
		span.innerHTML = "ok";
		span.className = "add_succeed";
		return true;
	}
}

/*当书籍页数文本框获取焦点的时候*/
function focusPage() {
	document.getElementById("check_book_page").innerHTML = "书籍页数的长度不能大于10，并且只能为数字";
	document.getElementById("check_book_page").className = "add_info";
	document.getElementById("page").className = "input_txtFocus";
}

/*当书籍页数文本框失去焦点的时候*/
function blurPage() {
	var book_page = document.getElementById("page");
	book_page.className = "input_text";
	var bookPage = book_page.value;

	var span = document.getElementById("check_book_page");
	/*验证填写的书籍是否正确*/
	var reg = /^([0-9]{1,10})[0-9]{0,10}([0-9]{0,10})$/g;
	if(bookPage.length <= 0) {
		span.innerHTML = "书籍的页数必须填写";
		span.className = "add_error";
		return false;
	} else if(bookPage.length > 10) {
		span.innerHTML = "书籍的页码数长度不可能超过10位数";
		span.className = "add_error";
		return false;
	} else if(reg.test(bookPage) == false) {
		span.innerHTML = "请检查是否填入非法的数字——只能为数字 ";
		span.className = "add_error";
		return false;
	} else {
		span.innerHTML = "ok";
		span.className = "add_succeed";
		return true;
	}
}

/*当作者输入文本框获得焦点的时候*/
function focusAuthor() {
	document.getElementById("check_book_author").innerHTML = "作者的长度不能大于100";
	document.getElementById("check_book_author").className = "add_info";
	document.getElementById("author").className = "input_txtFocus";
}

/*当书籍页数文本框失去焦点的时候*/
function blurAuthor() {
	var book_author = document.getElementById("author");
	book_author.className = "input_text";
	var bookAuthor = book_author.value;

	var span = document.getElementById("check_book_author");
	if(bookAuthor.length <= 0) {
		span.innerHTML = "作者名不能为空";
		span.className = "add_error";
		return false;
	} else if(bookAuthor.length > 50) {
		span.innerHTML = "作者长度不能大于50";
		span.className = "add_error";
		return false;
	} else {
		span.innerHTML = "ok";
		span.className = "add_succeed";
		return true;
	}
}
function filePath(){
	var value = document.getElementById('file_path').value;
	if(value.length<1 ||value==""){
		document.getElementById('check_book_file').innerHTML="请上传文件！";
		document.getElementById('check_book_file').className = "add_error";
		return false;
	}else{
		document.getElementById('check_book_file').innerHTML="ok";
		document.getElementById('check_book_file').className = "add_succeed";
		return true;
	}
}
function book_logo(){
	var value_300=document.getElementById('src_300').value;
	var value=document.getElementById('src').value;
	if((value_300.length<1 ||value_300=="") && (value.length<1 || value=="")){
		document.getElementById('check_book_logo').innerHTML="请上传书籍图片";
		document.getElementById('check_book_logo').className="add_error";
		return false;
	}
	document.getElementById('check_book_logo').innerHTML="ok";
	document.getElementById('check_book_logo').className="add_succeed";
	return true;
}
/* div.style.display='book_manager_show';  div.style.display='book_manager_hide';*/
function showBookManager(id){
	var div  = document.getElementById(id);
	 if(div.className=="book_manager_show"){
	 	div.className="book_manager_hide";
	 }else{
	 	div.className="book_manager_show";
	 }
}
/**
 * 上传我的书籍
**/
function uploadBook(){
	 var urlpath = "/control/book/upload_bookFile.go";
	winOpen(urlpath, "上传宝贝书籍", 850, 300);
}

function FCKeditorOnComplete(){
	//书籍分类验证
	if(focusType() && book_logo() && blurBookName() && blurPrice() && blurPage() && blurAuthor() && filePath()){
		var oEditor = FCKeditorAPI.GetInstance('HtmlEditor') ;
		document.getElementById("book_description").value=oEditor.GetXHTML();
		return true;
	}
	return false;
}
/*AJAX一般提交表单*/
function formSubmit(){
	//提交前数据校验
	FCKeditorOnComplete();
	 $('#add_book_form').ajaxSubmit(function(responseText) { 
         $("#right_content_sell").html(responseText);
     }); 

}